package com.ruoyi.base.service.impl;

import java.util.List;

import com.ruoyi.base.util.GenCodeUtils;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.base.mapper.ComponentClassificationMapper;
import com.ruoyi.base.domain.ComponentClassification;
import com.ruoyi.base.service.IComponentClassificationService;

/**
 * 构件分类Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-08-16
 */
@Service
public class ComponentClassificationServiceImpl implements IComponentClassificationService 
{
    @Autowired
    private ComponentClassificationMapper componentClassificationMapper;

    /**
     * 查询构件分类
     * 
     * @param id 构件分类主键
     * @return 构件分类
     */
    @Override
    public ComponentClassification selectComponentClassificationById(Long id)
    {
        return componentClassificationMapper.selectComponentClassificationById(id);
    }

    /**
     * 查询构件分类列表
     * 
     * @param componentClassification 构件分类
     * @return 构件分类
     */
    @Override
    public List<ComponentClassification> selectComponentClassificationList(ComponentClassification componentClassification)
    {
        return componentClassificationMapper.selectComponentClassificationList(componentClassification);
    }

    /**
     * 新增构件分类
     * 
     * @param componentClassification 构件分类
     * @return 结果
     */
    @Override
    public int insertComponentClassification(ComponentClassification componentClassification)
    {
        componentClassification.setCreateTime(DateUtils.getNowDate());
        SysUser user = SecurityUtils.getLoginUser().getUser();
        componentClassification.setCreateBy(user.getUserName());
        componentClassification.setCreateRole(user.getRoles().get(0).getRoleName());

        componentClassification.setCategoryCode(GenCodeUtils.getCategoryCode());
        return componentClassificationMapper.insertComponentClassification(componentClassification);
    }

    /**
     * 修改构件分类
     * 
     * @param componentClassification 构件分类
     * @return 结果
     */
    @Override
    public int updateComponentClassification(ComponentClassification componentClassification)
    {
        return componentClassificationMapper.updateComponentClassification(componentClassification);
    }

    /**
     * 批量删除构件分类
     * 
     * @param ids 需要删除的构件分类主键
     * @return 结果
     */
    @Override
    public int deleteComponentClassificationByIds(Long[] ids)
    {
        return componentClassificationMapper.deleteComponentClassificationByIds(ids);
    }

    /**
     * 删除构件分类信息
     * 
     * @param id 构件分类主键
     * @return 结果
     */
    @Override
    public int deleteComponentClassificationById(Long id)
    {
        return componentClassificationMapper.deleteComponentClassificationById(id);
    }

    /**
     * 构件分类字典
     *
     * @return 构件分类集合
     */
    @Override
    public List<ComponentClassification> getComponenTypeList(){
        return componentClassificationMapper.getComponenTypeList();
    }
}
